package cn.imnaer.service.rest.view.model;


import java.util.ArrayList;

import cn.imnaer.common.factory.JacksonUtil;

public class SimpleResponse {
    public static final String JSON_RESPONSE = "application/json;charset=UTF-8";
    public static final int ERROR_NONE = 0;
    public static final int ERROR_PARAM = 1;
    public static final int ERROR_PASSWORD = 2;
    public static final int DATA_EMPTY = 3;
    public static final int JSON_EXCEPTION = 4;
    public static final int ERROR_REPEAT = 5;
    public static final int USER_HAS = 6;
    public static final int ERROR_BLACK = 7;
    public static final int ERROR_NO_THIS_USER = 8;
    public static final int ERROR_COMMENT_DELETE = 9;
    public static final int ERROR_NO_THIS_PHOTO = 10;
    public static final int ERROR_AUTH = 11;
    public static final int ERROR_NO_THIS_SCENIC = 12;
    public static final int EMCHAT_ERROR = 14;
    public  static  final  String TYPE_ARRAY="ARRAY";
    public  static  final  String TYPE_OBJECT="OBJECT";

    /**
     * 邀请码错误
     */
    public static final int INVITE_ERROR = 15;
    /**
     * 用户不存在
     */
    public static final int USER_HAS_NOT_EXISTS = 16;
    /**
     * 发送邮件错误, 有可能超时, 有可能连接通, 都需要服务器查证
     */
    public static final int SEND_EMAIL_ERROR = 17;
    public static final int USER_PERMISSION_NOT_INIT = 18;
    public int code;
    public Object record;
	public  String type;
    public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
    public int getCode() {
        return code;
    }
    public void setCode(int code) {
        this.code = code;
    }
    public Object getRecord() {
        return record;
    }
    public void setRecord(Object record) {
        this.record = record;
    }
    public String success(Object record) {
    	   this.setCode(ERROR_NONE);
           this.setRecord(record);
           this.setType(TYPE_OBJECT);
       if(record==null){
    	   this.setCode(DATA_EMPTY);
           this.setRecord(record);
       }
        return JacksonUtil.beanToJson(this);

    }

    public String success() {
        this.setCode(ERROR_NONE);
        this.setRecord("");
        this.setType(TYPE_OBJECT);
        return JacksonUtil.beanToJson(this);

    }
    public String dataEmpty() {
        this.setCode(DATA_EMPTY);
        this.setRecord("");
        this.setType(TYPE_OBJECT);
        return JacksonUtil.beanToJson(this);
    }

    public String jsonException() {
        this.setCode(JSON_EXCEPTION);
        this.setRecord("");
        this.setType(TYPE_OBJECT);
        return JacksonUtil.beanToJson(this);
    }
    public <T> String toString(int code, T record) {
        this.setCode(code);
        this.setRecord(record);
        this.setType(TYPE_OBJECT);
        return JacksonUtil.beanToJson(this);
    }
    
    public  String  repeat(){
    	this.setCode(ERROR_REPEAT);
    	this.setType(TYPE_OBJECT);
    	return JacksonUtil.beanToJson(this);
    }

}
